
#include "EncodeMessageBuffer.h"
#include"pbc/pbc.h"
#include"MessageIDConst.h"
#include<iostream>

EncodeMessageBuffer::EncodeMessageBuffer()
{
    initEncoder();
}

EncodeMessageBuffer::~EncodeMessageBuffer()
{
}

EncodeBuff EncodeMessageBuffer::encode(pbc_env* env, Json::Value& data)
{
    auto id = data["messageid"].asInt();
    auto iter = m_encodeMaps.find(id);
    if (iter != m_encodeMaps.end())
    {
        return (this->*(iter->second))(env, data);
    }
    return EncodeBuff();
}


EncodeBuff EncodeMessageBuffer::encodeS2C_Login(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_Login");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "userId", data["userId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_GetAllMail(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_GetAllMail");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);

    int count = data["awards"].size();
    for (int awards_i = 0; awards_i < count; ++awards_i)
    {
        struct pbc_wmessage* awards = pbc_wmessage_message(encodeBuff.wmsg, "awards");
        pbc_wmessage_integer(awards, "type", data["awards"][awards_i]["type"].asInt(), 0);
        pbc_wmessage_integer(awards, "value", data["awards"][awards_i]["value"].asInt(), 0);
        pbc_wmessage_integer(awards, "size", data["awards"][awards_i]["size"].asInt(), 0);
    }

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_ReceivetMail(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_ReceivetMail");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "id", data["id"].asInt(), 0);

    int count = data["awards"].size();
    for (int awards_i = 0; awards_i < count; ++awards_i)
    {
        struct pbc_wmessage* awards = pbc_wmessage_message(encodeBuff.wmsg, "awards");
        pbc_wmessage_integer(awards, "type", data["awards"][awards_i]["type"].asInt(), 0);
        pbc_wmessage_integer(awards, "value", data["awards"][awards_i]["value"].asInt(), 0);
        pbc_wmessage_integer(awards, "size", data["awards"][awards_i]["size"].asInt(), 0);
    }

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_GetMail(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_GetMail");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);

    int count = data["mails"].size();
    for (int mails_i = 0; mails_i < count; ++mails_i)
    {
        struct pbc_wmessage* mails = pbc_wmessage_message(encodeBuff.wmsg, "mails");
        pbc_wmessage_integer(mails, "id", data["mails"][mails_i]["id"].asInt(), 0);
        pbc_wmessage_string(mails, "title", data["mails"][mails_i]["title"].asCString(), -1);
        pbc_wmessage_string(mails, "content", data["mails"][mails_i]["content"].asCString(), -1);

        int count = data["awards"].size();
        for (int awards_i = 0; awards_i < count; ++awards_i)
        {
            struct pbc_wmessage* awards = pbc_wmessage_message(mails, "awards");
            pbc_wmessage_integer(awards, "type", data["mails"][mails_i]["awards"][awards_i]["type"].asInt(), 0);
            pbc_wmessage_integer(awards, "value", data["mails"][mails_i]["awards"][awards_i]["value"].asInt(), 0);
            pbc_wmessage_integer(awards, "size", data["mails"][mails_i]["awards"][awards_i]["size"].asInt(), 0);
        }
    }

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_NorifyMail(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_NorifyMail");

    int count = data["mail"].size();
    for (int mail_i = 0; mail_i < count; ++mail_i)
    {
        struct pbc_wmessage* mail = pbc_wmessage_message(encodeBuff.wmsg, "mail");
        pbc_wmessage_integer(mail, "id", data["mail"][mail_i]["id"].asInt(), 0);
        pbc_wmessage_string(mail, "title", data["mail"][mail_i]["title"].asCString(), -1);
        pbc_wmessage_string(mail, "content", data["mail"][mail_i]["content"].asCString(), -1);

        int count = data["awards"].size();
        for (int awards_i = 0; awards_i < count; ++awards_i)
        {
            struct pbc_wmessage* awards = pbc_wmessage_message(mail, "awards");
            pbc_wmessage_integer(awards, "type", data["mail"][mail_i]["awards"][awards_i]["type"].asInt(), 0);
            pbc_wmessage_integer(awards, "value", data["mail"][mail_i]["awards"][awards_i]["value"].asInt(), 0);
            pbc_wmessage_integer(awards, "size", data["mail"][mail_i]["awards"][awards_i]["size"].asInt(), 0);
        }
    }

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_Register_User(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_Register_User");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_string(encodeBuff.wmsg, "usrName", data["usrName"].asCString(), -1);
    pbc_wmessage_string(encodeBuff.wmsg, "usrPsw", data["usrPsw"].asCString(), -1);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_GM_Excute(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_GM_Excute");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_UpdatePos(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_UpdatePos");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "userId", data["userId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);
    struct pbc_wmessage* forward = pbc_wmessage_message(encodeBuff.wmsg, "forward");
    pbc_wmessage_real(forward, "x", data["forward"]["x"].asDouble());
    pbc_wmessage_real(forward, "y", data["forward"]["y"].asDouble());
    pbc_wmessage_real(forward, "z", data["forward"]["z"].asDouble());
    struct pbc_wmessage* pos = pbc_wmessage_message(encodeBuff.wmsg, "pos");
    pbc_wmessage_real(pos, "x", data["pos"]["x"].asDouble());
    pbc_wmessage_real(pos, "y", data["pos"]["y"].asDouble());
    pbc_wmessage_real(pos, "z", data["pos"]["z"].asDouble());

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_UpdateVelocity(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_UpdateVelocity");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "userId", data["userId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);
    struct pbc_wmessage* pos = pbc_wmessage_message(encodeBuff.wmsg, "pos");
    pbc_wmessage_real(pos, "x", data["pos"]["x"].asDouble());
    pbc_wmessage_real(pos, "y", data["pos"]["y"].asDouble());
    pbc_wmessage_real(pos, "z", data["pos"]["z"].asDouble());
    struct pbc_wmessage* forward = pbc_wmessage_message(encodeBuff.wmsg, "forward");
    pbc_wmessage_real(forward, "x", data["forward"]["x"].asDouble());
    pbc_wmessage_real(forward, "y", data["forward"]["y"].asDouble());
    pbc_wmessage_real(forward, "z", data["forward"]["z"].asDouble());
    struct pbc_wmessage* velocity = pbc_wmessage_message(encodeBuff.wmsg, "velocity");
    pbc_wmessage_real(velocity, "x", data["velocity"]["x"].asDouble());
    pbc_wmessage_real(velocity, "y", data["velocity"]["y"].asDouble());
    pbc_wmessage_real(velocity, "z", data["velocity"]["z"].asDouble());

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_HeartBeat(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_HeartBeat");

    {
        int64_t temVar = data["time"].asInt64();
        int32_t hi = (uint32_t)(temVar >> 32);
        pbc_wmessage_integer(encodeBuff.wmsg, "time", (int32_t)temVar, hi);

    }

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_EnterScane(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_EnterScane");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "userId", data["userId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_PlayerLeaveView(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_PlayerLeaveView");
    pbc_wmessage_integer(encodeBuff.wmsg, "userId", data["userId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_NotifyName(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_NotifyName");
    pbc_wmessage_integer(encodeBuff.wmsg, "userId", data["userId"].asInt(), 0);
    pbc_wmessage_string(encodeBuff.wmsg, "userName", data["userName"].asCString(), -1);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_CheckNearPlayers(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_CheckNearPlayers");
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);

    int count = data["users"].size();
    for (int users_i = 0; users_i < count; ++users_i)
    {
        struct pbc_wmessage* users = pbc_wmessage_message(encodeBuff.wmsg, "users");
        pbc_wmessage_integer(users, "userId", data["users"][users_i]["userId"].asInt(), 0);
        pbc_wmessage_string(users, "userName", data["users"][users_i]["userName"].asCString(), -1);
    }

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_Chat(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_Chat");
    pbc_wmessage_integer(encodeBuff.wmsg, "senderId", data["senderId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "receiveId", data["receiveId"].asInt(), 0);
    pbc_wmessage_string(encodeBuff.wmsg, "content", data["content"].asCString(), -1);
    pbc_wmessage_string(encodeBuff.wmsg, "name", data["name"].asCString(), -1);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_CreateTeam(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_CreateTeam");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "teamId", data["teamId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "targetId", data["targetId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "leaderId", data["leaderId"].asInt(), 0);

    int count = data["members"].size();
    for (int members_i = 0; members_i < count; ++members_i)
    {
        struct pbc_wmessage* members = pbc_wmessage_message(encodeBuff.wmsg, "members");
        pbc_wmessage_integer(members, "userId", data["members"][members_i]["userId"].asInt(), 0);
        pbc_wmessage_string(members, "userName", data["members"][members_i]["userName"].asCString(), -1);
    }

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_InviteTeam(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_InviteTeam");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    struct pbc_wmessage* user = pbc_wmessage_message(encodeBuff.wmsg, "user");
    pbc_wmessage_integer(user, "userId", data["user"]["userId"].asInt(), 0);
    pbc_wmessage_string(user, "userName", data["user"]["userName"].asCString(), -1);
    pbc_wmessage_integer(encodeBuff.wmsg, "teamId", data["teamId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "targetId", data["targetId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_DelTeam(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_DelTeam");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "teamId", data["teamId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_QuitTeam(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_QuitTeam");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "userId", data["userId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "teamId", data["teamId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_NotifyTeam(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_NotifyTeam");
    struct pbc_wmessage* team = pbc_wmessage_message(encodeBuff.wmsg, "team");
    pbc_wmessage_integer(team, "teamId", data["team"]["teamId"].asInt(), 0);
    pbc_wmessage_integer(team, "leaderId", data["team"]["leaderId"].asInt(), 0);
    pbc_wmessage_integer(team, "targetId", data["team"]["targetId"].asInt(), 0);

    int count = data["members"].size();
    for (int members_i = 0; members_i < count; ++members_i)
    {
        struct pbc_wmessage* members = pbc_wmessage_message(encodeBuff.wmsg, "members");
        pbc_wmessage_integer(members, "userId", data["members"][members_i]["userId"].asInt(), 0);
        pbc_wmessage_string(members, "userName", data["members"][members_i]["userName"].asCString(), -1);
    }

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_OptInviteTeam(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_OptInviteTeam");
    struct pbc_wmessage* user = pbc_wmessage_message(encodeBuff.wmsg, "user");
    pbc_wmessage_integer(user, "userId", data["user"]["userId"].asInt(), 0);
    pbc_wmessage_string(user, "userName", data["user"]["userName"].asCString(), -1);
    pbc_wmessage_integer(encodeBuff.wmsg, "opt", data["opt"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_TeamGroupEnterScene(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_TeamGroupEnterScene");
    pbc_wmessage_integer(encodeBuff.wmsg, "teamId", data["teamId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_MonsterNotify(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_MonsterNotify");
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "monsterId", data["monsterId"].asInt(), 0);
    struct pbc_wmessage* pos = pbc_wmessage_message(encodeBuff.wmsg, "pos");
    pbc_wmessage_real(pos, "x", data["pos"]["x"].asDouble());
    pbc_wmessage_real(pos, "y", data["pos"]["y"].asDouble());
    pbc_wmessage_real(pos, "z", data["pos"]["z"].asDouble());
    pbc_wmessage_integer(encodeBuff.wmsg, "isFight", data["isFight"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_MonsterLeaveView(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_MonsterLeaveView");
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "monsterId", data["monsterId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_MonsterTrack(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_MonsterTrack");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "monsterId", data["monsterId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "trackId", data["trackId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_MonsterFight(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_MonsterFight");
    pbc_wmessage_integer(encodeBuff.wmsg, "ret", data["ret"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "monsterId", data["monsterId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "fightId", data["fightId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_LeaveMonsterTrack(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_LeaveMonsterTrack");
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "monsterId", data["monsterId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "trackId", data["trackId"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_MonsterLeaveFight(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_MonsterLeaveFight");
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "monsterId", data["monsterId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "success", data["success"].asInt(), 0);

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

EncodeBuff EncodeMessageBuffer::encodeS2C_NotifyMonsterStatus(pbc_env* env, Json::Value& data)
{
    EncodeBuff encodeBuff;
    encodeBuff.slice = new pbc_slice;
    encodeBuff.wmsg = pbc_wmessage_new(env, "tutorial.S2C_NotifyMonsterStatus");
    pbc_wmessage_integer(encodeBuff.wmsg, "sceneId", data["sceneId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "monsterId", data["monsterId"].asInt(), 0);
    pbc_wmessage_integer(encodeBuff.wmsg, "status", data["status"].asInt(), 0);
    struct pbc_wmessage* topos = pbc_wmessage_message(encodeBuff.wmsg, "topos");
    pbc_wmessage_real(topos, "x", data["topos"]["x"].asDouble());
    pbc_wmessage_real(topos, "y", data["topos"]["y"].asDouble());
    pbc_wmessage_real(topos, "z", data["topos"]["z"].asDouble());

    pbc_wmessage_buffer(encodeBuff.wmsg, encodeBuff.slice);
    return encodeBuff;
}

void EncodeMessageBuffer::initEncoder()
{
    m_encodeMaps[ID_S2C_Login] = &EncodeMessageBuffer::encodeS2C_Login;
    m_encodeMaps[ID_S2C_GetAllMail] = &EncodeMessageBuffer::encodeS2C_GetAllMail;
    m_encodeMaps[ID_S2C_ReceivetMail] = &EncodeMessageBuffer::encodeS2C_ReceivetMail;
    m_encodeMaps[ID_S2C_GetMail] = &EncodeMessageBuffer::encodeS2C_GetMail;
    m_encodeMaps[ID_S2C_NorifyMail] = &EncodeMessageBuffer::encodeS2C_NorifyMail;
    m_encodeMaps[ID_S2C_Register_User] = &EncodeMessageBuffer::encodeS2C_Register_User;
    m_encodeMaps[ID_S2C_GM_Excute] = &EncodeMessageBuffer::encodeS2C_GM_Excute;
    m_encodeMaps[ID_S2C_UpdatePos] = &EncodeMessageBuffer::encodeS2C_UpdatePos;
    m_encodeMaps[ID_S2C_UpdateVelocity] = &EncodeMessageBuffer::encodeS2C_UpdateVelocity;
    m_encodeMaps[ID_S2C_HeartBeat] = &EncodeMessageBuffer::encodeS2C_HeartBeat;
    m_encodeMaps[ID_S2C_EnterScane] = &EncodeMessageBuffer::encodeS2C_EnterScane;
    m_encodeMaps[ID_S2C_PlayerLeaveView] = &EncodeMessageBuffer::encodeS2C_PlayerLeaveView;
    m_encodeMaps[ID_S2C_NotifyName] = &EncodeMessageBuffer::encodeS2C_NotifyName;
    m_encodeMaps[ID_S2C_CheckNearPlayers] = &EncodeMessageBuffer::encodeS2C_CheckNearPlayers;
    m_encodeMaps[ID_S2C_Chat] = &EncodeMessageBuffer::encodeS2C_Chat;
    m_encodeMaps[ID_S2C_CreateTeam] = &EncodeMessageBuffer::encodeS2C_CreateTeam;
    m_encodeMaps[ID_S2C_InviteTeam] = &EncodeMessageBuffer::encodeS2C_InviteTeam;
    m_encodeMaps[ID_S2C_DelTeam] = &EncodeMessageBuffer::encodeS2C_DelTeam;
    m_encodeMaps[ID_S2C_QuitTeam] = &EncodeMessageBuffer::encodeS2C_QuitTeam;
    m_encodeMaps[ID_S2C_NotifyTeam] = &EncodeMessageBuffer::encodeS2C_NotifyTeam;
    m_encodeMaps[ID_S2C_OptInviteTeam] = &EncodeMessageBuffer::encodeS2C_OptInviteTeam;
    m_encodeMaps[ID_S2C_TeamGroupEnterScene] = &EncodeMessageBuffer::encodeS2C_TeamGroupEnterScene;
    m_encodeMaps[ID_S2C_MonsterNotify] = &EncodeMessageBuffer::encodeS2C_MonsterNotify;
    m_encodeMaps[ID_S2C_MonsterLeaveView] = &EncodeMessageBuffer::encodeS2C_MonsterLeaveView;
    m_encodeMaps[ID_S2C_MonsterTrack] = &EncodeMessageBuffer::encodeS2C_MonsterTrack;
    m_encodeMaps[ID_S2C_MonsterFight] = &EncodeMessageBuffer::encodeS2C_MonsterFight;
    m_encodeMaps[ID_S2C_LeaveMonsterTrack] = &EncodeMessageBuffer::encodeS2C_LeaveMonsterTrack;
    m_encodeMaps[ID_S2C_MonsterLeaveFight] = &EncodeMessageBuffer::encodeS2C_MonsterLeaveFight;
    m_encodeMaps[ID_S2C_NotifyMonsterStatus] = &EncodeMessageBuffer::encodeS2C_NotifyMonsterStatus;
}
